package com.example.bicycle.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.util.SaResult;
import com.example.bicycle.domain.dto.SearchRecordsDto;
import com.example.bicycle.domain.dto.UserLocationDto;
import com.example.bicycle.service.RideRecordService;
import org.springframework.web.bind.annotation.*;

@SaCheckLogin
@RestController
@RequestMapping("/record/")
public class RecordController {
    private final RideRecordService rideRecordService;

    public RecordController(RideRecordService rideRecordService) {
        this.rideRecordService = rideRecordService;
    }

    @PostMapping("listByUserIdOrBikeId")
    public SaResult listBy(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize, @RequestBody SearchRecordsDto searchRecordsDto) {
        return SaResult.data(rideRecordService.getRecordsByUserIdOrBikeId(pageNum, pageSize, searchRecordsDto));
    }

    @PostMapping("list")
    public SaResult listBy(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize) {
        return SaResult.data(rideRecordService.getAllRecords(pageNum, pageSize));
    }

    @PostMapping("listByUserId")
    public SaResult listByUserId(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize, @RequestParam("userId") int userId) {
        return SaResult.data(rideRecordService.getRecordsByUserId(pageNum, pageSize, userId));
    }

    @PostMapping("listByBikeId")
    public SaResult listByBikeId(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize, @RequestParam("bikeId") int bikeId) {
        return SaResult.data(rideRecordService.getRecordsByBikeId(pageNum, pageSize, bikeId));
    }
    @PostMapping("listByUserIdAndBikeId")
    public SaResult listByUserIdAndBikeId(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize, @RequestParam("userId") int userId, @RequestParam("bikeId") int bikeId) {
        return SaResult.data(rideRecordService.getRecordsByUserIdAndBikeId(pageNum, pageSize, userId, bikeId));
    }
}
